<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #app {
            width: 802px;
            height: 100vh;
            margin: 0 auto;
            border: 1px solid black;
            box-sizing: border-box;
        }

        .box {
            width: 200px;
            height: 200px;
            border: 1px solid black;
            box-sizing: border-box;
            float: left;
        }

        .main {
            width: 100%;
            height: 100px;
            border: 1px solid black;
            clear: both;
        }
    </style>
</head>

<body>
    <div id="app">
        <div class="box" name="盒子1" data-index="0">这是第一个盒子</div>
        <div class="box" name="盒子2" data-index="0">这是第二个盒子</div>
        <div class="box" name="盒子3" data-index="0">这是第三个盒子</div>
        <div class="box" name="盒子4" data-index="0">这是第四个盒子</div>
        <div id="main">main</div>
    </div>

</body>
<script>
    let box = document.getElementsByClassName('box')
    for (let i = 0, len = box.length; i < len; i++) {
        box[i].onclick = function () {
            //获得元素的属性，开始标签中的key="value"
            let clazz = this.getAttribute("class")
            console.log(clazz)
            let name = this.getAttribute("name")
            console.log(name)
            let index = this.getAttribute("data-index")
            console.log(index)
            let str = `class="${clazz}",name="${name}",date-index="${index}"`
            main.innerHTML = str
            this.removeAttribute("name")
        }
    }
</script>

</html>